﻿using System;
using System.Security.Permissions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Blog.TemplateViewEngine
{
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class TemplateControllerFactory : DefaultControllerFactory, IControllerFactory
    {
        protected override IController CreateController(RequestContext context, string controllerName)
        {
            Controller controller = (Controller)base.CreateController(context, controllerName);

            controller.ViewEngine = new TemplateViewFactory();

            return controller;
        }

        IController IControllerFactory.CreateController(RequestContext context, string controllerName)
        {
            return CreateController(context, controllerName);
        }

        void IControllerFactory.DisposeController(IController controller)
        {
            DisposeController(controller);
        }
    }
}
